using PPIDataAccess.General;
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace PPIDataAccess.Data
{
	public static class DUtility_QueryPolygon_Point
	{
		#region Query
        public static DataSet SelectAllByQuery(Int32 Utility_QueryPolygonId, string connectionkey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryPolygon_Points_SelectAllByQuery", DBHelper.GetConnection(connectionkey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryPolygonId", ParameterDirection.Input, false, Utility_QueryPolygonId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryPolygon_Points_SelectAllByQuery", _Ex);
            }
            finally
            {
                if (_Da != null) _Da.SelectCommand.Connection.Close();
            }
        }
        #region summary
		/// <summary>
		/// Date: 05/12/2008
		/// Time: 13:58:38
		/// Generated by: VMCoder
		/// Generated using VirtualGenerator
		/// </summary>
		#endregion summary
        public static DataSet SelectAll(string connectionkey)
		{
			SqlDataAdapter _Da = null;
			try
			{
                _Da = new SqlDataAdapter("up_Utility_QueryPolygon_Points_SelectAll", DBHelper.GetConnection(connectionkey));
				_Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataSet _Dt = new DataSet();
				_Da.Fill(_Dt);
				return _Dt;
			}
			catch (Exception _Ex)
			{
                throw new Exception("Error executing up_Utility_QueryPolygon_Points_SelectAll", _Ex);
			}
			finally
			{
				if (_Da != null) _Da.SelectCommand.Connection.Close();
			}
		}
		#endregion Query

		#region CRUD
		#region summary
		/// <summary>
		/// Date: 05/12/2008
		/// Time: 13:58:38
		/// Generated by: VMCoder
		/// Generated using VirtualGenerator
		/// </summary>
		#endregion summary
        public static Int32 Insert(Int32 utility_QueryPolygonFK, double latitude, double longitude, string connectionkey)
		{
			SqlCommand _Cmd = null;
            try
            {
                _Cmd = new SqlCommand("up_tb_Utility_QueryPolygon_Points_Insert", DBHelper.GetConnection(connectionkey));

                _Cmd.CommandType = CommandType.StoredProcedure;
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryPolygonFK", ParameterDirection.Input, false, utility_QueryPolygonFK));
                _Cmd.Parameters.Add(DBHelper.CreateFloatParameter("@Latitude", ParameterDirection.Input, false, latitude));
                _Cmd.Parameters.Add(DBHelper.CreateFloatParameter("@Longitude", ParameterDirection.Input, false, longitude));

                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryPolygon_PointId", ParameterDirection.ReturnValue, false, 0));
                _Cmd.ExecuteNonQuery();
                return (Int32)_Cmd.Parameters["@Utility_QueryPolygon_PointId"].Value;

            }
            finally
            {
                if (_Cmd != null) _Cmd.Connection.Close();
            }
        }
		#region summary
		/// <summary>
		/// Date: 05/12/2008
		/// Time: 13:58:38
		/// Generated by: VMCoder
		/// Generated using VirtualGenerator
		/// </summary>
		#endregion summary
        public static void Delete(Int32 utility_QueryPolygon_PointId, string connectionkey)
		{
			SqlCommand _Cmd = null;
			SqlTransaction _Tr = null;
			try
			{
                _Cmd = new SqlCommand("up_tb_Utility_QueryPolygon_Points_Delete", DBHelper.GetConnection(connectionkey));
				_Tr = _Cmd.Connection.BeginTransaction();
				_Cmd.Transaction = _Tr;
				_Cmd.CommandType = CommandType.StoredProcedure;
				_Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryPolygon_PointId", ParameterDirection.Input, false, utility_QueryPolygon_PointId));
				_Cmd.ExecuteNonQuery();
				_Tr.Commit();
			}
			catch (Exception _Ex)
			{
				if (_Tr != null)
					_Tr.Rollback();
                throw new Exception("Error executing up_tb_Utility_QueryPolygon_Points_Delete", _Ex);
			}
			finally
			{
				if (_Cmd != null) _Cmd.Connection.Close();
			}
		}
        #region summary
        /// <summary>
        /// Date: 05/12/2008
        /// Time: 13:58:38
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public static void DeleteByQuery(Int32 utility_QueryPolygonFk, string connectionkey)
        {
            SqlTransaction _Tr = null;
            SqlCommand _Cmd = null;

            try
            {
                _Cmd = new SqlCommand("up_tb_Utility_QueryPolygon_Points_DeleteByQuery", DBHelper.GetConnection(connectionkey));
                _Tr = _Cmd.Connection.BeginTransaction();
                _Cmd.Transaction = _Tr;
                _Cmd.CommandType = CommandType.StoredProcedure;
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryPolygonFk", ParameterDirection.Input, false, utility_QueryPolygonFk));
                _Cmd.ExecuteNonQuery();
                _Tr.Commit();
            }
            catch (Exception)
            {
                if (_Tr != null)
                    _Tr.Rollback();
                throw;
            }
            finally
            {
                if (_Cmd != null) _Cmd.Connection.Close();
            }
        }
        #endregion CRUD
	}
}

